package learning.spring.binarytea.config;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.stereotype.Component;

import java.util.Objects;

@Component
@Endpoint(id = "shop")
public class ShopEndpoint {
    private BinaryTeaProperties binaryTeaProperties;

    public ShopEndpoint(ObjectProvider<BinaryTeaProperties> binaryTeaProperties) {
        this.binaryTeaProperties = binaryTeaProperties.getIfAvailable();
    }

    @ReadOperation
    public String state() {
      if (Objects.isNull(binaryTeaProperties) || !binaryTeaProperties.isReady()) {
          return "We are not ready.";
      } else {
          return "We will open " + binaryTeaProperties.getOpenHours() + ".";
      }
    }
}
